<script>
function clonecontent (firstinput,secondinput){
	var inputed = $("#"+firstinput+"").val();
	$("#"+secondinput+"").val(inputed);
}
function countTextchars (textare, tospan, addit){
	var len = textare.value.length;
	$(tospan).text(len+'/'+addit);
}
function populateTextArea(uniqueForm,uniqueID,summaredarea){
  var output = new Array();
  var fieldID = 0;
  while (temprow= document.getElementById(uniqueID+fieldID)){
    temptag= document.getElementById(uniqueID+fieldID+"-tag");
    output[fieldID]=temptag.value+temprow.value;
	fieldID++;
  };
  output = jQuery.grep(output, function(n){ return (n); });
  document.getElementById(summaredarea).value = output.join('\n');
  document.getElementById('r_'+summaredarea).value = output.join('\n');
}
function clearTextArea(uniqueID){
	var answer = confirm("Поискахте изтриване на превод:\n"+document.getElementById(uniqueID).value+"\n\nПотвърждавате ли заявката си?\n\nN.B. Изтриванете е необратимо!");
	if (answer){
		document.getElementById(uniqueID).value = "";
		document.getElementById(uniqueID+"_t").value = "";
		document.getElementById(uniqueID+"-tag").value = "";
	}
}
function clearBox(elementID){
    document.getElementById(elementID).innerHTML = "";
}
function parseselection(){
	getSelText('keyword'); getSelText('keysearch'); getSelText('dict_word'); getSelText('wordEN')
}
</script>
<script>
$(document).keydown(function(e) {
	if(e.altKey){
		if(e.keyCode==87){$("#srch-wiki").click(); e.preventDefault();} 
		else if(e.keyCode==71){$("#srch-ggle").click(); e.preventDefault();} 
		else if(e.keyCode==84){$("#srch-gtr").click(); e.preventDefault();} 
		else if(e.keyCode==83){$("#srch-cms").click(); e.preventDefault();} 
		else if(e.keyCode==68){
			var keyword = $("#keyword").val();
			$("#enbgwordFOUND").load("enbg.php?word="+keyword.trim()+" "+"#sresult");
			e.preventDefault();}
	}
	if(!$(e.target).is('input, textarea')){
		if(e.ctrlKey){
			if(e.which===37){$('#prev-trans')[0].click(); e.preventDefault();} 
			else if(e.which===39){$('#next-trans')[0].click(); e.preventDefault();}
		}
		else if(e.which===37){$('#prev-page')[0].click(); e.preventDefault();}    
		else if(e.which===39){$('#next-page')[0].click(); e.preventDefault();}
	}
	else if(e.ctrlKey){
		function valadd(number) {
			$('#'+id+'').val($('#'+id+'').val()+$('#CTRL'+number+'-text').val());
			e.preventDefault();
		}
		var id= $("*:focus").attr("id");
		if(e.keyCode===49){valadd(1);}      else if(e.keyCode===54){valadd(6);}
		else if(e.keyCode===50){valadd(2);} else if(e.keyCode===55){valadd(7);}
		else if(e.keyCode===51){valadd(3);} else if(e.keyCode===56){valadd(8);}
		else if(e.keyCode===52){valadd(4);} else if(e.keyCode===59){valadd(9);}
		else if(e.keyCode===53){valadd(5);}
	}
	if(e.ctrlKey&&e.which===13){$('#send-trans')[0].click(); e.preventDefault();} 
	if(e.which===27){$("#sresult-button").click(); e.preventDefault();}  
});
$(document).ready(function(){
	$("#savectrls").click(function() {
		var datastring='';
		for (var i = 1; i <= 9; i++) {
			itxt=$("input#CTRL"+i+"-text").val();
			if(datastring.length>0){datastring+='&';}
			datastring += 'CTRL'+i+'='+itxt;
		}
		datastring=encodeURI(datastring);
		$.ajax({  
			type: "POST",  
			url: "viewtext-savectrls.php",  
			data: datastring,  
			success: function() {
				$('#savectrls-message').html("<div class='textGREEN'>Запаметени!</div>").fadeIn(1000).fadeOut(5000);
			}
		});
		return false;  
	});
	$("#savedict").click(function() {
		var wordEN= $("input#wordEN").val(); var wordBG= $("input#wordBG").val();
		if(wordEN.length>0 && wordEN!=' ' &&  wordBG.length>0 && wordBG!=' ') {
			datastring= 'wordEN='+wordEN+'&wordBG='+wordBG;
			//datastring=encodeURI(datastring);
			$.ajax({  
				type: "POST",  
				url: "viewtext-savedict.php?game=<?php echo $CMS_game;?>", 
				data: datastring,  
				success: function() {
					$('#savedict-message').html("<div class='textGREEN'>Въведено!</div>").fadeIn(1000).fadeOut(5000);
					$("input#wordEN").val(''); $("input#wordBG").val('');
				}
			});
			return false;
		}
	});	
});
</script>
<script>
function hideBLOC(rowID) {
	$("#"+rowID+"").hide("slow");
}
function showBLOC(rowID) {
	$("#"+rowID+"").show("slow");
}
function toggleBLOC(rowID) {
	if( !$("#"+rowID+"").is(':visible') ) {
		$("#"+rowID+"").show("slow");}
	else $("#"+rowID+"").hide("slow");
}
</script>
<script>
function toggle_hidden_note_textarea(notenum) {
	var editarea = "#note"+notenum+"_editarea";
	var showndiv = "#note"+notenum+"_content";
	if ($(editarea).css("display")=="none") {
		$(editarea).css("display","block");
		$(showndiv).css("display","none");
	} else {
		$(editarea).css("display","none");
		$(showndiv).css("display","block");
	}
	var notecontent = $(showndiv).html();
	$("#note"+notenum+"_editfield").html(notecontent);
};
function post_hidden_note_textarea(notenum) {
	var editarea = "#note"+notenum+"_editarea";
	var showndiv = "#note"+notenum+"_content";
	var statsdiv = "#note"+notenum+"_status";
	var changedcontent = $("#note"+notenum+"_editfield").val();
	$.ajax({
		url: "viewtext-notes.php",
		type: "POST",
		data: { id: notenum, content: changedcontent, action: "edit" },
        beforeSend: function(){
			$(statsdiv).fadeIn(250).html('Запазване...');
		},
		success: function(){
			$(statsdiv).fadeIn(250).html('Успешно запазено!').delay(2500).fadeOut(250);
			$(showndiv).text(changedcontent);	
		},
		error: function(){
			$(statsdiv).fadeIn(250).html('Случи се грешка!').delay(2500).fadeOut(250);
		}
	});
	$(showndiv).css("display","block");
	$(editarea).css("display","none");
}
function delete_note_from_notes_table(notenum) {
	var result = confirm("Да се изтрие?");
	var showndiv = "#note"+notenum+"_content";
	if (result==true) {
		$.ajax({
			url: "viewtext-notes.php",
			type: "POST",
			data: { id: notenum, action: "del" },
			success: function(){
				$(showndiv).html("(Изтрит коментар! Ще изчезне от списъка при презареждане на страницата.)");	
			}
		});
	}
}
function note_add_new() {
	var content = $("#note_add_new").val();
	var statsdiv = "#note_add_new_status";
	if (content!="Вашият коментар..." && content!="" && content!=" ") {
		$.ajax({
			url: "viewtext-notes.php",
			type: "POST",
			data: { content: content, game: "<?=$CMS_game;?>", userid: "<?=USERID;?>", username: "<?=USERNAME;?>", action: "add" },
			beforeSend: function(){
				$(statsdiv).fadeIn(250).html('Запазване...');
			},
			success: function(){
				$(statsdiv).fadeIn(250).html('Успешно запазено!').delay(2500).fadeOut(250);
				var new_note = "<div class='forumheader3'><div class='forumheader'><?=USERNAME;?></div>(Добавен коментар! Ще се уеднакви със списъка при презареждане на страницата.) "+content+"</div>";
				var new_notes_list = new_note+$("#notes_container").html();
				$("#notes_container").html(new_notes_list);
			},
			error: function(){
				$(statsdiv).fadeIn(250).html('Случи се грешка!').delay(2500).fadeOut(250);
			}
		});
	} else alert("Опитвате се да изпратите празен текст.");
}
</script>
<script>
function approve_shananigans_exec(transid,fullrow_changed,fullrow_receiving,numrows){
	var fullrow_changed_val = $("#"+fullrow_changed+"").val();
	$("#"+fullrow_receiving+"").val(fullrow_changed_val);
	var fullrows = new Array();
	for (var i=0;i<numrows;i++) {
		fullrows[i]= $("#r_"+transid+i+"-tag").val()+$("#r_"+transid+i).val();
	}
	var	total; total = fullrows.join('\n');
	$("#trans_"+transid).val(total);
	$("#r_trans_"+transid).val(total);
}
</script>